/**
 * postMessage通信hooks
 * @param iframe iframe DOM元素
 * @param funcName 方法名数组
 * @param property 参数数组
 */
export const usePostMessage = (iframe, funcName, property) => {
  if (!iframe || !funcName || !property) {
    console.error('postMessage参数错误')
    return
  }

  // 确保数组长度一致
  if (funcName.length !== property.length) {
    console.error('postMessage参数数组长度不一致')
    return
  }

  // 发送消息给iframe
  for (let i = 0; i < funcName.length; i++) {
    const message = {
      funcName: funcName[i],
      property: property[i]
    }
    iframe.contentWindow.postMessage(message, '*')
  }
} 